package v.show.health.client;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.env.EnvironmentPostProcessor;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.MapPropertySource;

import java.util.HashMap;
import java.util.Map;

/**
 * @author whzhang
 */
@Slf4j
public class DefaultClientManagement implements EnvironmentPostProcessor {

    @Override
    public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
        Map<String, Object> map = new HashMap<>(20);
        // http client export
        map.put("management.endpoints.web.exposure.include", "*");
        map.put("management.endpoints.web.exposure.exclude", EnvHelper.getValue(environment, "${actuator.exclude:beans}"));

        // 关闭shutdown endpoint
        map.put("management.endpoint.shutdown.enabled", "false");
        map.put("management.endpoint.health.show-details", "always");

        // jmx 只暴露health,info
        map.put("management.endpoints.jmx.exposure.include", "health,info");

        // enable prometheus
        map.put("management.metrics.export.prometheus.enabled", "true");
        map.put("management.endpoint.prometheus.enabled", "true");

        MapPropertySource source = new MapPropertySource("DefaultClientManagement", map);
        environment.getPropertySources().addLast(source);
    }
}
